{# **
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 * #}

<div id="customerCard" class="customer card">
  <div class="card-header">
    <h3 class="card-header-title">
      {{ 'Customer'|trans({}, 'Admin.Global') }}
    </h3>
  </div>

  <div class="card-body">
    <div id="customerInfo" class="info-block">
      <div class="row">
        {% if orderForViewing.customer is not null and orderForViewing.customer.id != 0 %}
          <div class="col-xxl-7">
            <h2 class="mb-0">
              <i class="material-icons">account_box</i>
              {{ orderForViewing.customer.gender }}
              {{ orderForViewing.customer.firstName }}
              {{ orderForViewing.customer.lastName }}
            </h2>
          </div>
          <div id="viewFullDetails" class="col-xxl-5 text-xxl-right">
            <a class="d-print-none btn btn-primary btn-sm" href="{{ path('admin_customers_view', {customerId: orderForViewing.customer.id}) }}">
              {{ 'View details'|trans({}, 'Admin.Actions') }}
            </a>
          </div>
        {% else %}
          <div class="col">
            <h2 class="mb-0">{{ 'Deleted customer'|trans({}, 'Admin.Global') }}</h2>
          </div>
        {% endif %}
      </div>

      {% if orderForViewing.customer.groups %}
        <div class="customer-groups mt-2">
          {% for group in orderForViewing.customer.groups %}
            <span class="badge">{{ group }}</span>
          {% endfor %}
        </div>
      {% endif %}

    </div>
    {% if orderForViewing.customer is not null and orderForViewing.customer.id != 0 %}
      <div class="info-block mt-2">
        <p class="mb-0" id="customerId"><strong>{{ 'ID:'|trans({}, 'Admin.Global') }}</strong> {{ orderForViewing.customer.id }}</p>
        <p class="mb-0" id="customerEmail"><strong>{{ 'Email:'|trans({}, 'Admin.Global') }}</strong> <a href="mailto:{{ orderForViewing.customer.email }}">{{ orderForViewing.customer.email }}</a></p>
        <p class="mb-0"><strong>{{ 'Customer type:'|trans({}, 'Admin.Global') }}</strong>
          {% if orderForViewing.customer.isGuest is same as(false) %}
            {{ 'Registered customer'|trans({}, 'Admin.Global') }}
          {% else %}
            {{ 'Guest customer'|trans({}, 'Admin.Global') }}
          {% endif %}
        </p>
        {% if orderForViewing.customer.isGuest is same as(false) %}
          <p class="mb-0"><strong>{{ 'Account registered:'|trans({}, 'Admin.Orderscustomers.Feature') }}</strong> {{ orderForViewing.customer.accountRegistrationDate|date_format_full }}</p>
          <p class="mb-0"><strong>{{ 'Total spent since registration:'|trans({}, 'Admin.Orderscustomers.Feature') }}</strong> {{ orderForViewing.customer.totalSpentSinceRegistration }}</p>
          <p class="mb-0" id="validatedOrders"><strong>{{ 'Validated orders placed:'|trans({}, 'Admin.Orderscustomers.Feature') }}</strong> {{ orderForViewing.customer.validOrdersPlaced }}</p>
        {% endif %}
        {% if orderForViewing.customer.siret is not empty %}
        <p class="mb-0"><strong>{{ 'SIRET'|trans({}, 'Admin.Orderscustomers.Feature') }}</strong> {{ orderForViewing.customer.siret }}</p>
        {% endif %}
        {% if orderForViewing.customer.ape is not empty %}
        <p class="mb-0"><strong>{{ 'APE'|trans({}, 'Admin.Orderscustomers.Feature') }}</strong> {{ orderForViewing.customer.ape }}</p>
        {% endif %}
      </div>
    {% endif %}
    <div class="info-block mt-2">
      <div class="row">
        {% if orderForViewing.virtual is same as(false) %}
          <div id="addressShipping" class="info-block-col col-xl-6">
            <div class="row justify-content-between no-gutters">
              <strong>{{ 'Shipping address'|trans({}, 'Admin.Orderscustomers.Feature') }}</strong>
              {% if orderForViewing.customer is not null and orderForViewing.customer.id != 0 %}
                <a class="tooltip-link d-print-none" href="#" data-toggle="dropdown">
                  <i class="material-icons">more_vert</i>
                </a>

                <div class="dropdown-menu dropdown-menu-right">
                  <a class="dropdown-item" id="js-delivery-address-edit-btn"
                     href="{{ path('admin_order_addresses_edit', {orderId: orderForViewing.id, addressType: 'delivery', liteDisplaying: 1, submitFormAjax: 1}) }}"
                  >
                    {{ 'Edit existing address'|trans({}, 'Admin.Actions') }}
                  </a>

                  <a href="#"
                     class="dropdown-item js-update-customer-address-modal-btn"
                     data-toggle="modal"
                     data-target="#updateCustomerAddressModal"
                     data-address-type="shipping"
                  >
                    {{ 'Select another address'|trans({}, 'Admin.Actions') }}
                  </a>
                </div>
              {% endif %}
            </div>

            {% for line in orderForViewing.shippingAddressFormatted|split('\n') %}
              <p class="mb-0">{{ line }}</p>
            {% endfor %}
          </div>
        {% endif %}
        <div id="addressInvoice" class="info-block-col {% if orderForViewing.virtual %}col-md-12{% else %}col-xl-6{% endif %}">
          <div class="row justify-content-between no-gutters">
            <strong>{{ 'Invoice address'|trans({}, 'Admin.Orderscustomers.Feature') }}</strong>

            {% if orderForViewing.customer is not null and orderForViewing.customer.id != 0 %}
              <a class="tooltip-link d-print-none" href="#" data-toggle="dropdown">
                <i class="material-icons">more_vert</i>
              </a>

              <div class="dropdown-menu dropdown-menu-right">
                <a class="dropdown-item" id="js-invoice-address-edit-btn"
                   href="{{ path('admin_order_addresses_edit', {orderId: orderForViewing.id, addressType: 'invoice', liteDisplaying: 1, submitFormAjax: 1}) }}"
                >
                  {{ 'Edit existing address'|trans({}, 'Admin.Actions') }}
                </a>

                <a href="#"
                   class="dropdown-item js-update-customer-address-modal-btn"
                   data-toggle="modal"
                   data-target="#updateCustomerAddressModal"
                   data-address-type="invoice"
                >
                  {{ 'Select another address'|trans({}, 'Admin.Actions') }}
                </a>
              </div>
            {% endif %}
          </div>

          {% for line in orderForViewing.invoiceAddressFormatted|split('\n') %}
            <p class="mb-0">{{ line }}</p>
          {% endfor %}
        </div>
      </div>
    </div>

    {% if orderForViewing.customer is not null and orderForViewing.customer.id != 0 and privateNoteForm is not null %}
      <div id="privateNote" class="mt-2 info-block">
        <div class="row">
          {% set isPrivateNoteOpen = not orderForViewing.customer.privateNote is empty %}

          <div class="col-md-6">
            <h3 class="mb-0{{ not isPrivateNoteOpen ? ' d-print-none' : '' }}">
              {{ 'Customer private note'|trans({}, 'Admin.Orderscustomers.Feature') }}
            </h3>
          </div>
          <div class="col-md-6 text-right d-print-none">
            <a href="#"
               class="float-right tooltip-link js-private-note-toggle-btn {% if isPrivateNoteOpen %}is-opened{% endif %}"
            >
              {% if isPrivateNoteOpen %}
                <i class="material-icons">remove</i>
              {% else %}
                <i class="material-icons">add</i>
              {% endif %}
            </a>
          </div>

          <div class="col-md-12 mt-3 js-private-note-block {% if not isPrivateNoteOpen %}d-none{% endif %}">
            {{ form_start(privateNoteForm, {
              action: path('admin_customers_set_private_note', {
                customerId: orderForViewing.customer.id,
                back: path('admin_orders_view', {orderId: orderForViewing.id})
              })
              }) }}

              {{ form_widget(privateNoteForm.note) }}
              <div class="d-none">
                {{ form_rest(privateNoteForm) }}
              </div>

              <div class="mt-2 text-right">
                <button type="submit"
                        class="btn btn-primary btn-sm js-private-note-btn"
                        {% if orderForViewing.customer.privateNote is empty %}disabled{% endif %}
                >
                  {{ 'Save'|trans({}, 'Admin.Actions') }}
                </button>
              </div>
            {{ form_end(privateNoteForm) }}
          </div>
        </div>
      </div>
    {% endif %}
  </div>
</div>
